import UIKit

public class Layouttools: NSObject {
    

    
    class public func createLable(_ frame : CGRect,lableText:String = "",textColor : UIColor? = UIColor.black,largeFont : CGFloat,smallFont : CGFloat,backgroundColor : UIColor = UIColor.white)->UILabel {
        
        let lable = UILabel(frame: frame.integral)
        lable.textColor = textColor
        lable.text = lableText
        lable.backgroundColor = backgroundColor
        lable.font = UIFont.systemFont(ofSize: largeFont)
        return lable
    }

    
    class public func createSingleBlueButton(_ frameY : CGFloat,buttonOriginX:CGFloat = 10,titleLable : String,target : AnyObject?, action : Selector?,imageName : String,largeFont : CGFloat,smallFont : CGFloat ,buttonWidth:CGFloat) ->UIButton{
        
        let button = PmsSingleBlueButton(width:buttonWidth)
        button.frame.origin = CGPoint(x: buttonOriginX, y: frameY)
        button.setTitle(titleLable, for: UIControl.State())
        if target != nil && action != nil {
            button.addTarget(target,action: action!,for: UIControl.Event.touchUpInside)
        }
        //button.addTarget(target,action: action,forControlEvents: UIControl.Event.TouchUpInside)
        return button
    }
    
    class public func createLineLable(_ frame : CGRect, color : UIColor,alpha :CGFloat = 0.4) ->UILabel {
        let lable = UILabel(frame: frame)
        lable.backgroundColor = color
        lable.alpha=alpha
        return lable
    }
    
    class public func createSingleButtonWithImageView(_ frame:CGRect,target:AnyObject?,action:Selector,imageName:String) -> UIButton{
        
        let button = UIButton(frame: frame)
        button.addTarget(target,action: action,for: UIControl.Event.touchUpInside)
        if  let buttonImage = UIImage(named: imageName) {
            let leftImageView = UIImageView(frame: CGRect(x: (frame.size.width-buttonImage.size.width)/2, y: (frame.size.height-buttonImage.size.height)/2, width: buttonImage.size.width, height: buttonImage.size.height))
            leftImageView.image = buttonImage
            button.addSubview(leftImageView)
        }
        return button
    }

    class public func createButton(_ frame:CGRect,titleText:String = "",target:AnyObject?,action:Selector,textColor:UIColor? = CommonColors.c_5264cc,font:CGFloat,backgroundColor:UIColor = UIColor.white) -> UIButton{
        let button = UIButton(frame: frame)
        button.setTitle(titleText, for: UIControl.State())
        button.titleLabel!.font = UIFont.systemFont(ofSize: font)
        button.backgroundColor = backgroundColor
        button.setTitleColor(textColor, for: UIControl.State())
        button.addTarget(target,action: action,for: UIControl.Event.touchUpInside)
        return button
    }
}

extension Double {
    /** 保留小数点后面2位。小数点前面每隔3位用逗号分开 */
    public func toMoneyWithOutIcon() -> String {
        let formatter = NumberFormatter()
        //formatter.numberStyle = .DecimalStyle
        formatter.positiveFormat = "###,##0.00;"
        formatter.allowsFloats = false
        return formatter.string(from: NSNumber(value: self))!
    }
    
}

